<%@ page import="com.kyub.spring.gears.vo.NavigableCollection" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="spring-sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="cf" uri="http://kyub.com/jsp/jstl/functions" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net/el" %>
<%@ taglib prefix="gears" uri="http://kyub.com/jsp/jstl/crud" %>

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insertTemplate template="/tiles/classic.jsp">

    <tiles:putAttribute name="scripts">
        <!--
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/thickbox.js"></script>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/thickbox.css" type="text/css" media="screen"/>
        -->
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript"
                src="${pageContext.request.contextPath}/js/jquery-ui-1.7.2.custom.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.form.js"></script>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/smoothness/jquery-ui-1.7.2.custom.css"
              type="text/css" media="screen"/>
        <script type="text/javascript">
            $(document).ready(function() {
                doInit();
            });
            function doInit() {
                initList();
                initSearch();
            }
            function initList() {
                $("#formDialog").dialog({
                    bgiframe: true,
                    autoOpen: false,
                    height: 576,
                    width: 770,
                    modal: true,
                    title: '<spring:message code="${pojoDescriptor.name}.labelForm" text="Edit ${pojoDescriptor.name}"
                        htmlEscape="true"/>',
                    buttons: {
                        '<spring:message code="${pojoDescriptor.name}.submitForm" text="Save"
                        htmlEscape="true"/>': function() {

                            var options = {
                                target:        '#formDialog',   // target element(s) to be updated with server response
                                success:       checkResult  // post-submit callback
                            }

                            $('#pojoForm').ajaxSubmit(options);

                            // !!! Important !!!
                            // always return false to prevent standard browser submit and page navigation
                            return false;

                        }
                    }
                });
            }

            function initSearch() {
                $('#search_${pojoDescriptor.name}').submit(function() {

                    var options = {
                        target:        '#${pojoDescriptor.name}_list',   // target element(s) to be updated with server response
                        beforeSubmit:  startProgress_${pojoDescriptor.name},  // pre-submit callback
                        success:       stopProgress_${pojoDescriptor.name}  // post-submit callback

                    };




                    $('#search_${pojoDescriptor.name}').ajaxSubmit(options);
                     
                    // !!! Important !!!
                    // always return false to prevent standard browser submit and page navigation
                    return false;
                });
            }

            function checkResult() {

                if ($('#formDialog > form').size() == 0) {
                     
                    $('#formDialog').dialog('close');


                    $("#${pojoDescriptor.name}_list").fadeOut("slow", function() {

                        $("#${pojoDescriptor.name}_list").load('${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/rialist',{_searchString : $('#_searchString').val() }, function(responseText, textStatus, XMLHttpRequest) {
                            $("#${pojoDescriptor.name}_list").fadeIn('slow');
                         
                        });
                    });


               }

            }

            function shiftPage(page){
                $("#${pojoDescriptor.name}_list").fadeOut("slow", function() {

                        $("#${pojoDescriptor.name}_list").load('${pageContext.request.contextPath}/${gears_restfull_prefix}/${pojoDescriptor.name}/rialist&LIST_PAGE_PARAM=' + page,{_searchString : $('#_searchString').val() }, function(responseText, textStatus, XMLHttpRequest) {
                            $("#${pojoDescriptor.name}_list").fadeIn('slow');

                        });
                    });
            }


            function openFormDialog(urlParam) {
                initList();
                $("#formDialog").load(urlParam, function(responseText, textStatus, XMLHttpRequest) {

                    if (textStatus == 'error') {
                        $('#formDialog').html(responseText);
                    }
                    $('#formDialog').dialog('open');

                });
            }
            function openDisplayDialog(urlParam,height, width){
                initList();
                $("#formDialog").load(urlParam, function(responseText, textStatus, XMLHttpRequest) {

                    if (textStatus == 'error') {
                        $('#formDialog').html(responseText);
                    }
                    $('#formDialog').dialog('open');

                });
            }
        </script>


    </tiles:putAttribute>
    <tiles:putAttribute name="body">
       


        <gears:ria-search pojoDescriptor="${pojoDescriptor }" gears_restfull_prefix="${gears_restfull_prefix}"/>
        
        <div id="formDialog">

    </div>
        
        <div id="${pojoDescriptor.name}_list">
            <gears:ria-list pojoDescriptor="${pojoDescriptor}" pojoList="${pojoList}"
                            gears_restfull_prefix="${gears_restfull_prefix}"/>

        </div>
    </tiles:putAttribute>
</tiles:insertTemplate>